﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VaccineEbook.Models.DBEntity;
using System.Text;
namespace VaccineEbook.Models
{
    public partial class CheckData
    {
        
        public static int CheckUser(string username)
        {
            VaccineEBookEntities _db = null;
            User user = null;
            try
            {
                _db = new VaccineEBookEntities();            
                user = _db.Users.Where(u => u.Username == username).SingleOrDefault() ;
               // user = from u in _db.Users where u.Username == username select u;
                if (user != null)
                    return 0;
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -2;
            }
            finally
            {                
                _db = null;
                GC.Collect();

            }
        }

        public static int CheckTokenID(string tokenID, int userId)
        {
            VaccineEBookEntities _db = null;
            Token token = null;
            try
            {
                _db = new VaccineEBookEntities();
                token = _db.Tokens.Where(tk => tk.tokenID == tokenID).SingleOrDefault();
                if (token != null)
                    return 0;
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -2;
            }
            finally
            {                
                _db = null;
                GC.Collect();

            }

        }

      
    }
}